<template>
	<view class="prescriptionList-wrap">
		<view class="prescriptionList-label" v-if="dataList.length > 0">
			<u-title value="处方列表"></u-title>
			<scroll-view show-scrollbar="false" class="scroll-list " scroll-y @scrolltolower="scrollLoading()">
				<u-presc-item v-for="(item, index) in dataList" :key="index" :data="item"
					@click="gotoRouter('/pages-doctor/prescInfo/prescInfo?id=' + item.id + '&role=0')"></u-presc-item>
			</scroll-view>
		</view>
		<u-empty-state v-if="dataTotalPage == 0" value="暂无相关处方"></u-empty-state>
		<uni-load-more v-if="dataTotalPage > 1" :status="dataLoading"></uni-load-more>
	</view>
</template>

<script>
	import uTitle from '@/components/u-title/u-title.vue';
	import uPrescItem from '@/components/u-presc-item/u-presc-item.vue';
	import uniLoadMore from '@/components/uni/uni-load-more/uni-load-more.vue';
	import uEmptyState from '@/components/u-empty-state/u-empty-state.vue';
	export default {
		components: {
			uTitle,
			uniLoadMore,
			uEmptyState,
			uPrescItem
		},
		data() {
			return {
				pageNo: 1,
				pageSize: 20,
				dataTotalPage: 1, //数据总数
				dataLoading: 'loading', //数据加载
				dataList: [],
				id: null
			};
		},
		onLoad(option) {
			this.id = option.id
		},
		onShow() {
			this.initData();
		},
		methods: {
			initData(e) {
				this.pageNo = 1;
				this.dataList = [];
				this.dataTotalPage = 1;

				this.scrollLoading();
			},

			//问诊订单列表
			queryUserRecipePage() {
				this.$api
					.listById({
						params: {
							pageNo: this.pageNo,
							pageSize: this.pageSize,
							id: this.id
						}
					})
					.then(res => {
						if (res.code == 200) {
							res.result.records.forEach(key => {
								key.recipeDetailDTO = JSON.parse(key.content);
							});
							this.dataTotalPage = res.result.pages;

							if (this.pageNo == 1) {
								this.dataList = res.result.records;
							} else {
								this.dataList = this.dataList.concat(res.result.records);
							}

							if (res.result.current >= res.result.pages) {
								this.dataLoading = 'noMore';
							} else {
								this.dataLoading = 'loading';
							}
							this.pageNo++;
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							});
						}
					});
			},

			//滚动加载
			scrollLoading() {
				if (this.pageNo <= this.dataTotalPage) {
					this.queryUserRecipePage();
				}
			}
		}
	};
</script>

<style lang="less">
	.prescriptionList-wrap {
		padding: 20rpx 32rpx;
		box-sizing: border-box;

		.prescriptionList-label {
			width: 686rpx;
			background: #ffffff;
			box-shadow: 0px 2rpx 10rpx 0px rgba(0, 0, 0, 0.1);
			border-radius: 16rpx;
			box-sizing: border-box;
			padding: 20rpx 30rpx;

			.scroll-list {
				height: calc(100vh - 140rpx);
				padding-top: 20rpx;
				box-sizing: border-box;

				&::-webkit-scrollbar {
					display: none;
				}
			}
		}
	}
</style>